/**
 * 调用API统一方法
 * Created by Administrator on 2019-08-20.
 */
var pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2HL0Wr+F2JkD2TZOoB0kJW9onz0HL52zjhIZxXKO71b72XEtMRujAxu0jZneHfKdST55t3wZ9xLgx21kTqMB9q/RtCq4x5HT/0cTCCae/i4wwi484hsG/SYynLAdZbV4GEiqQ0HZU/aPPenLe7NY0+5N2Bg8KqseKFdWPzaccxQIDAQAB";
var url = "http://localhost:9090/rest/";
var format = "json";
var contentType = "application/json";
var defaultAccessId = "afe87ec38c974da19805a9a92172d53c";
/**
 * 调用服务器接口
 * @param action
 * @param accessId
 * @param userId
 */
function request(action, accessId, userId, json, params) {
    var data;
    var ContentType = "application%2Fjson";
    if (accessId == '') {
        accessId = defaultAccessId;
    }
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(pubKey);
    var str = "Content-Type=" + ContentType + "&action=" + action + "&accessId=" + accessId + "&format=" + format + "&userId=" + userId + "&reqObject=" + encodeURIComponent(params);

    console.log(str);
    console.log(params);

    var sign = encrypt.encryptLong(str);

    console.log(sign);

    $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        data: JSON.stringify({
            reqObject: json
        }),
        cache: false,
        async: false,
        headers: {
            "action": action,
            'Content-Type': contentType,
            'accessId': accessId,
            'format': format,
            'userId': userId,
            'sign': sign
        },
        success: function (res) {
            data = res.data;
            console.log(data);
        },
        error: function (e) {
            alert(e);
        }
    });
    return data;
}
